<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>key</title>
</head>

<body>
    <div id="app">
        <!-- in 后面放过 普通数组 对象数组 对象 数字 -->
        <div>
            <label>id:
                <input type="text" v-model="id" />
            </label>
            <label>name:
                <input type="text" v-model="name" />
            </label>
            <input type="button" value="添加" @click='add'>
        </div>

        <!-- v-for 循环的时候key只能用number或者string -->
        <!-- 在组件中使用v-for循环的时候，或者在一些特殊的情况下使用v-for必须使用key值 -->
        <p v-for="item in list" :key='item.id'>
            <input type="checkbox">{{item.id}}---{{ item.name }}
        </p>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                id: '',
                name: '',
                list: [
                    { id: 1, name: "111" },
                    { id: 2, name: "555" },
                    { id: 3, name: "333" },
                    { id: 4, name: "444" }
                ]
            },
            methods:{
                add(){
                    // this.list.push({id:this.id,name:this.name})
                    this.list.unshift({id:this.id,name:this.name})
                }
            }
        });
    </script>
</body>

</html>